home *** CD-ROM | disk | FTP | other *** search
/ APDL Other Worlds / APDL Other Worlds Collection.iso / SF3000 / Extras / !SFskyedit / c / SFSIconbar < prev    next >
Encoding:
Text File  |  2003-10-16  |  4.1 KB  |  134 lines

  1. /*
  2.  *  SFskyedit - Star Fighter 3000 sky colours editor
  3.  *  Iconbar icon
  4.  *  Copyright (C) 2001  Chris Bazley
  5.  *
  6.  *  This program is free software; you can redistribute it and/or modify
  7.  *  it under the terms of the GNU General Public Licence as published by
  8.  *  the Free Software Foundation; either version 2 of the Licence, or
  9.  *  (at your option) any later version.
  10.  *
  11.  *  This program is distributed in the hope that it will be useful,
  12.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  *  GNU General Public Licence for more details.
  15.  *
  16.  *  You should have received a copy of the GNU General Public Licence
  17.  *  along with this program; if not, write to the Free Software
  18.  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  */
  20.  
  21. /* ANSI library files */
  22. #include <stdlib.h>
  23. #include <stdio.h>
  24. #include <string.h>
  25. #include <stdbool.h>
  26.  
  27. /* RISC OS library files */
  28. #include "wimp.h"
  29. #include "toolbox.h"
  30. #include "event.h"
  31. #include "wimplib.h"
  32. #include "iconbar.h"
  33. #include "flex.h"
  34.  
  35. /* My library files */
  36. #include "err.h"
  37. #include "msgtrans.h"
  38. #include "Macros.h"
  39. #include "Loader.h"
  40. #include "SFformats.h" /* get Fednet filetype */
  41. #include "ViewsMenu.h"
  42. #include "NoBudge.h"
  43.  
  44. /* Local headers */
  45. #include "EditSky.h"
  46. #include "SFSIconbar.h"
  47. #include "Utils.h"
  48.  
  49. static ObjectId Iconbar_id;
  50.  
  51. /* ----------------------------------------------------------------------- */
  52. /*                       Function prototypes                               */
  53.  
  54. static ToolboxEventHandler _Iconbar_click;
  55.  
  56. /* ----------------------------------------------------------------------- */
  57. /*                         Public functions                                */
  58.  
  59. void Iconbar_initialise(ObjectId id)
  60. {
  61.   Iconbar_id = id;
  62.  
  63.   /* Listen for ADJUST clicks */
  64.   EF(event_register_toolbox_handler(id, Iconbar_Clicked, _Iconbar_click, NULL));
  65.  
  66.   /* Register listeners for files dropped on iconbar icon */
  67.   EF(loader_register_listener(LISTENER_CLAIM, FILETYPE_SKYCOLS, id, NULL, load_compressed, Iconbar_openfile, NULL));
  68. }
  69.  
  70. /* ----------------------------------------------------------------------- */
  71.  
  72. void Iconbar_openfile(char *title, bool data_saved, flex_ptr buffer, int filetype, void *handle)
  73. {
  74.   ObjectId editing_win;
  75.  
  76.   /* Check for existing windows */
  77.   if(!data_saved || (editing_win = ViewsMenu_findview(title)) == NULL_ObjectId) {
  78.  
  79.     /* Check file format */
  80.     if(!verify_sky_file((SF_SkyColours **)buffer)) {
  81.       flex_free(buffer);
  82.       return;
  83.     }
  84.  
  85.     /* Create editing window */
  86.     editing_win = EditSky_create((SF_SkyColours **)buffer, title, data_saved);
  87.     if(editing_win == NULL_ObjectId) {
  88.       flex_free(buffer);
  89.       return;
  90.     }
  91.   }
  92.   else
  93.     flex_free(buffer); /* Already have an open editing window */
  94.  
  95.   /* Open editing window */
  96.   RE(show_win_at_ptr(0, editing_win, Iconbar_id, NULL_ComponentId));
  97. }
  98.  
  99. /* ----------------------------------------------------------------------- */
  100. /*                         Private functions                               */
  101.  
  102. static int _Iconbar_click(int event_code, ToolboxEvent *event, IdBlock *id_block, void *handle)
  103. {
  104.   ObjectId editing_win;
  105.   SF_SkyColours *new_sky;
  106.  
  107.   if(FLAG_SET(((IconbarClickedEvent *)event)->hdr.flags, Iconbar_Clicked_Select)) {
  108.     /* Initialise blank sky */
  109.     if(!flex_alloc((flex_ptr)&new_sky, sizeof(SF_SkyColours)))
  110.       MG_RETV("NoMem", 1); /* claim event */
  111.  
  112.     new_sky->min_sky_height = 0;
  113.     new_sky->min_stars_height = 0;
  114.     nobudge_register(256);
  115.     memset(new_sky->shade, 0, 126*sizeof(unsigned int));
  116.     nobudge_deregister();
  117.  
  118.     /* Open editing window */
  119.     editing_win = EditSky_create((SF_SkyColours **)&new_sky, "<untitled>", 0);
  120.     if(editing_win == NULL_ObjectId)
  121.       flex_free((flex_ptr)&new_sky);
  122.     else
  123.       RE(toolbox_show_object(0, editing_win, Toolbox_ShowObject_Centre, NULL, id_block->self_id, NULL_ComponentId));
  124.     return 1; /* claim event */
  125.   }
  126.  
  127.   if(FLAG_SET(((IconbarClickedEvent *)event)->hdr.flags, Iconbar_Clicked_Adjust)) {
  128.     /* bring all open windows to front */
  129.     RE(ViewsMenu_showall());
  130.     return 1; /* claim event */
  131.   }
  132.   return 0; /* not handled */
  133. }
  134.